using System;
using System.Collections.Generic;
using System.Linq;
using DataAccess.BusinessEntities;

namespace DataAccess.UnitTests
{
    public class DataTestBase
    {
        public DataTestBase()
        {
            this.InitializeRepositories();
        }

        protected void InitializeRepositories()
        {
            this.StoreData = StoreObjectMother.CreateStores().ToList();
            this.StoreRepository = new InMemoryRepository<Store>(this.StoreData);
            this.UserData = UserObjectMother.CreateUsers().ToList();
            this.UserRepository = new InMemoryRepository<User>(this.UserData);
            this.PersonalLocationData = PersonalLocationObjectMother.CreatePersonalLocations().ToList();
            this.PersonalLocationRepository = new InMemoryRepository<PersonalLocation>(this.PersonalLocationData);
            this.ProductData = ProductObjectMother.CreateProducts().ToList();
            this.ProductRepository = new InMemoryRepository<Product>(this.ProductData);
            this.SubstanceData = SubstanceObjectMother.CreateSubstances().ToList();
            this.SubstanceRepository = new InMemoryRepository<Substance>(this.SubstanceData);
            this.ContainerData = ContainerObjectMother.CreateContainers().ToList();
            this.ContainerRepository = new InMemoryRepository<Container>(this.ContainerData);

            this.UnitOfWork = new InMemoryUnitOfWork();
            this.UnitOfWork.Stores = this.StoreRepository;
            this.UnitOfWork.Users = this.UserRepository;
            this.UnitOfWork.PersonalLocations = this.PersonalLocationRepository;
            this.UnitOfWork.Products = this.ProductRepository;
            this.UnitOfWork.Substances = this.SubstanceRepository;
            this.UnitOfWork.Containers = this.ContainerRepository;

            this.DomainContext = new InMemoryDomainContext();
            this.DomainContext.Populate<Product>(this.ProductData);
            this.DomainContext.Populate<Store>(this.StoreData);
            this.DomainContext.Populate<User>(this.UserData);
            this.DomainContext.Populate<PersonalLocation>(this.PersonalLocationData);
            this.DomainContext.Populate<Substance>(this.SubstanceData);
            this.DomainContext.Populate<Container>(this.ContainerData);

            this.DomainContext.PopulateDictionary<Product>(this.ProductData);
            this.DomainContext.PopulateDictionary<Store>(this.StoreData);
            this.DomainContext.PopulateDictionary<User>(this.UserData);
            this.DomainContext.PopulateDictionary<PersonalLocation>(this.PersonalLocationData);
            this.DomainContext.PopulateDictionary<Substance>(this.SubstanceData);
            this.DomainContext.PopulateDictionary<Container>(this.ContainerData);
        }

        protected IList<Store> StoreData { get; set; }
        protected InMemoryRepository<Store> StoreRepository { get; set; }
        protected IList<User> UserData { get; set; }
        protected InMemoryRepository<User> UserRepository { get; set; }
        protected IList<PersonalLocation> PersonalLocationData { get; set; }
        protected InMemoryRepository<PersonalLocation> PersonalLocationRepository { get; set; }
        protected IList<Product> ProductData { get; set; }
        protected InMemoryRepository<Product> ProductRepository { get; set; }
        protected IList<Substance> SubstanceData { get; set; }
        protected InMemoryRepository<Substance> SubstanceRepository { get; set; }
        protected IList<Container> ContainerData { get; set; }
        protected InMemoryRepository<Container> ContainerRepository { get; set; }
        protected InMemoryUnitOfWork UnitOfWork { get; set; }

        protected InMemoryDomainContext DomainContext { get; set; }
    }
}
